chunk_size = 1024 * 1024  # 每次读取1MB
with open('largefile.txt', 'r') as file:
    while True:
        chunk = file.read(chunk_size)
        if not chunk:
            break
        process_chunk(chunk)  # 假设有一个函数process_chunk用来处理每个数据块